package com.cnswhy.cloud.server.merchant.controller.shop;

import com.cnswhy.cloud.common.core.base.R;
import com.cnswhy.cloud.common.core.base.controller.SuperController;
import com.cnswhy.cloud.server.core.dao.ShopSpecValueMapper;
import com.cnswhy.cloud.server.core.dto.ShopSpecValuePageDTO;
import com.cnswhy.cloud.server.core.dto.ShopSpecValueSaveDTO;
import com.cnswhy.cloud.server.core.dto.ShopSpecValueUpdateDTO;
import com.cnswhy.cloud.server.core.entity.ShopSpecValue;
import com.cnswhy.cloud.server.core.service.ShopSpecValueService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
//import com.github.zuihou.security.annotation.PreAuth;


/**
 * <p>
 * 前端控制器
 * 规格值表
 * </p>
 *
 * @author cnswhy
 * @date 2020-11-07
 */
@Slf4j
@Validated
@RestController
@RequestMapping("/shopSpecValue")
@Api(value = "ShopSpecValue", tags = "规格值表")
//@PreAuth(replace = "shopSpecValue:")
public class ShopSpecValueController extends SuperController<ShopSpecValueService, Long, ShopSpecValue, ShopSpecValuePageDTO, ShopSpecValueSaveDTO, ShopSpecValueUpdateDTO> {
    @Autowired
    ShopSpecValueMapper shopSpecValueMapper;
    @PostMapping("/querySpecValueList")
    public R<List<ShopSpecValue>> querySpecValueList(@RequestBody ShopSpecValuePageDTO shopSpecValuePageDTO) {
        List<ShopSpecValue> shopSpecValueList = shopSpecValueMapper.querySpecValueList(shopSpecValuePageDTO.getProductId(),shopSpecValuePageDTO.getSpecId());
        return success(shopSpecValueList);
    }
    /**
     * Excel导入后的操作
     *
     * @param list
     */
    @Override
    public R<Boolean> handlerImport(List<Map<String, String>> list){
        List<ShopSpecValue> shopSpecValueList = list.stream().map((map) -> {
            ShopSpecValue shopSpecValue = ShopSpecValue.builder().build();
            return shopSpecValue;
        }).collect(Collectors.toList());

        return R.success(baseService.saveBatch(shopSpecValueList));
    }
}
